column
Purpose
Customizes a column definition
Examples
static mapping = { currency column: "currency", sqlType: "char", length: 3 }
Description
Usage: property_name(map)
Arguments:
column
- The name of the column as a StringsqlType
(optional) - The underlying SQL typeenumType
(optional) - The enum type in for type-safe Enum properties. Eitherordinal
orstring
.index
(optional) - The index nameunique
(optional) - Whether it is uniquelength
(optional) - The length of the columnprecision
(optional) - The precision of the columnscale
(optional) - The scale of the columncomment
(optional) - The comment for the column (used to create the table DDL)defaultValue
(optional) - The database default value
By default GORM uses the property name and type to determine how to map a property in the database. For example a String
property is typically mapped as a varchar(255)
column. You can customize these with column configuration arguments:
static mapping = { currency column: "currency", sqlType: "char", length: 3 }
If you use a Hibernate type that requires multiple column definitions you can use the column
method to define each column:
static mapping = { amount type: MonetaryUserType, { column name: "value" column name: "currency", sqlType: "char", length: 3 } }
Note that if you have a static method that is the same name as one of your properties you are trying to configure or you use the same property name as one of the static GORM methods this can lead to conflicts. To avoid this scenario scope the mapping configuration using the delegate
property:
static mapping = { delegate.currency column: "currency", sqlType: "char", length: 3 }